var template = require('./template');
var core = require('core');
var wechat = core.wechat;

var text = function(callback){
    // var res = new template.text(this);
    // res.Content = "你好";

    // var res;
    // if(this.Content !== "龚文硕"){
    //     res = new template.text(this);
    //     res.Content = "您好";
    // }else{
    //     res = new template.news(this);
    //     res.ArticleCount = 3;
    //
    //     for(var i = 0; i < 3; i++){
    //         var item = new template.news.item();
    //         item.Title = "测试_"+(i+1);
    //         item.Description = item.Title;
    //         item.PicUrl = "http://fanyi.baidu.com/static/translation/img/header/logo_cbfea26.png";
    //         item.Url = "http://www.baidu.com/";
    //
    //         res.Articles.item.push(item);
    //     }
    // }
    if(this.Content === "管理"){
        var openid = this.FromUserName;
        var param = {
            openid: openid,
            $or: JSON.stringify([
                {tagid_list : wechat.config.tagid_contrast[1]},
                {tagid_list : wechat.config.tagid_contrast[2]},
                {tagid_list : wechat.config.tagid_contrast[3]}
            ])
        };
        var that = this;
        core.api("user/getUser", param, function(err, doc){
            if(!err && !doc.code && doc.docs){
                var res = new template.text(that);
                res.Content = '<a href="'+ wechat.config.URL +'admin/home">点击进入管理平台</a>';
            }else
                var res = "";
            callback(res);
        });
    }else{
        var res = "";
        callback(res);
    }
};

module.exports = text;
